package com.example.testservice.controller;

import com.example.testservice.model.MailNotifyConfig;
import com.example.testservice.model.SmsNotifyConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author pactera
 * @since 2021-08-13 星期五 9:45
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/notify-config")
public class NotifyConfigController {

  private static final Logger LOGGER = LoggerFactory.getLogger(NotifyConfigController.class);

  private final Set<String> statusChanges = new HashSet<>(Collections.singleton("UP:OFFLINE"));

  private final Map<String, Object> additionalProperties = new HashMap<>();

  {
    this.statusChanges.add("UNKNOWN:OFFLINE");
    this.additionalProperties.put("name", "Alice");
    this.additionalProperties.put("age", 123);
  }

  @GetMapping("/get-mail")
  public List<MailNotifyConfig> getMail(String id) {
    LOGGER.info("The api /notify-config/get-mail called. Params: [{}]", id);
    List<MailNotifyConfig> configs = new ArrayList<>();
    MailNotifyConfig config = new MailNotifyConfig("1001-1", true, "Administration<localhost>", "tmp.html", null, new String[]{"alice@qq.com"}, new String[]{"bob@qq.com"}, statusChanges, additionalProperties);
    configs.add(config);
    return configs;
  }

  @GetMapping("/get-sms")
  public List<SmsNotifyConfig> getSms(String id) {
    LOGGER.info("The api /notify-config/get-mail called. Params: [{}]", id);
    List<SmsNotifyConfig> configs = new ArrayList<>();
    List<String> mobileList = Collections.singletonList("13234567890");
    SmsNotifyConfig config = new SmsNotifyConfig("1001-2", true, "60010101", null, mobileList, statusChanges, additionalProperties);
    configs.add(config);
    return configs;
  }
}
